package com.redxiii.spike.pmi.trac;

import com.redxiii.spike.api.command.CommandFactory;
import com.redxiii.spike.api.command.InitializationRequired;
import com.redxiii.spike.api.pmi.entity.Member;
import com.redxiii.spike.pmi.HandlerSession;
import com.redxiii.spike.pmi.command.GenCommitWork;
import com.redxiii.spike.pmi.commons.DefaultTimeEntry;
import com.redxiii.spike.pmi.commons.PmiDatabase;
import com.redxiii.spike.util.message.BasicMsgInterpreter;

/**
 * @author Daniel Filgueiras
 * 04/05/2011
 */
@CommandFactory(BasicMsgInterpreter.class)
@InitializationRequired
public class DbCommitWork extends GenCommitWork {

	@Override
	protected boolean commit() {
		
		PmiDatabase db = HandlerSession.getDatabase();
		Member author = db.getMemberByMail(remoteId);
		
		DefaultTimeEntry timeEntry = new DefaultTimeEntry(issue, author);
		timeEntry.setWorkedTime(workedTime);
		timeEntry.setComment(userSettings.getIssueComment());
		
		return db.commitWork(timeEntry) != null;
	}
}
